package com.mioto.ld.module.alert.statistic;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.mioto.ld.module.device.model.DeviceAlertCounterStatisticsVO;

/**
 * @author mioto-qinxj
 * @date 2024/6/15
 * @desc
 */
public class DeviceAlertWeekStatistics extends AbstractDeviceAlertStatistics {
    public DeviceAlertWeekStatistics() {
        this.index = 7;
    }

    @Override
    protected DeviceAlertCounterStatisticsVO[] genDeviceAlertCounterStatisticsVO() {
        DeviceAlertCounterStatisticsVO[] deviceAlertCounterStatisticsVOS = new DeviceAlertCounterStatisticsVO[index];
        DateTime dateTime;
        for (int i = 0; i < index; i++) {
            dateTime = DateUtil.offsetDay(startDate,i);
            deviceAlertCounterStatisticsVOS[i] = new DeviceAlertCounterStatisticsVO();
            deviceAlertCounterStatisticsVOS[i].setFormatDate(DateUtil.format(dateTime,DatePattern.NORM_DATE_PATTERN));
            deviceAlertCounterStatisticsVOS[i].setTime(buildTimeStr(i));
        }
        return deviceAlertCounterStatisticsVOS;
    }

    @Override
    protected void calculateDate(String startTime, String endTime) {
        this.endDate = DateUtil.dateSecond();
        this.startDate =DateUtil.beginOfDay(DateUtil.offsetDay(endDate, -index + 1));
    }

    @Override
    protected String buildTimeStr(int index) {
        DateTime dateTime = DateUtil.offsetDay(startDate,index);
        int num = dateTime.dayOfMonth();
        if (num < 10){
            return "0" + num;
        }
        return num + "";
    }
}
